<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>企业后台管理</title>
    {load href="/static/layui/css/layui.css"}
    {load href="/static/layui/layui.js"}
</head>
<body style="background: #1E9FFF">
    <div style="position:absolute;left: 50%;top: 50%;width: 500px;margin-left: -250px;margin-top: -200px;">
        <div style="background:#FFFFFF;padding: 20px;border-radius: 4px;box-shadow: 5px 5px 5px #444444">
            <div class="layui-form-item">
                <h2>用户登陆</h2>
                <hr>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" name="uname" id="uname" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="pwd" id="pwd" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码：</label>
                <div class="layui-input-inline">
                    <input type="text" name="captcha" id="captcha" required  lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input" >
                </div>
                <img id="captchaimg" src="{:captcha_src()}" alt="captcha" onclick="this.src=this.src+'?'+Math.random()"/>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="dologin();">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>
    <script src="/static/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        layui.use(['layer'],function(){
            $ = layui.jquery;
            layer = layui.layer;

            // 用户名控件获取焦点
            $('#uname').focus();
            // 回车登录
            $('input').keydown(function(e){
                if(e.keyCode == 13){
                    dologin();
                }
            });
        });

        // 重新生成验证码
        function reloadImg(){
            $('#captchaimg').attr('src','{:captcha_src()}?rand='+Math.random());
        }

        function dologin() {

            var uname = $.trim($('#uname').val());
            var pwd = $.trim($('#pwd').val());
            var captcha = $.trim($('#captcha').val());

            if(uname == ''){
                layer.alert('请输入用户名',{icon:2});
                return false;
            }
            if(pwd == ''){
                layer.alert('请输入密码',{icon:2});
                return;
            }
            if(captcha==''){
                layer.alert('请输入验证码',{icon:2});
                return;
            }
            $.post("{:url('login')}",{'uname':uname,'pwd':pwd,'captcha':captcha},function(res){
                if(res.code==0){
                    layer.msg(res.msg);
                    setTimeout(function(){window.location.href = '/index.php/bm'},1000);
                }else{
                    reloadImg();
                    layer.alert(res.msg,{icon:2});
                }
            },'json');
        }

    </script>
</body>
</html>